package com.airlines.crewassignment.controller.crew;



import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.airlines.base.entity.user.User;
import com.airlines.common.Page;
import com.airlines.common.R;
import com.airlines.crewassignment.entity.crew.CrewConflict;
import com.airlines.crewassignment.service.crew.CrewConflictService;

/**
 * @author pxy
 * @date 2018/05/17 15:27:03
 * @company xxxx Airlines
 * @description 人员冲突(不根据人员分类)
 */
@Controller
@RequestMapping("/crewConflict")
public class CrewConflictController {

    private static final String PREFIX = "/crew";

    @Autowired
    CrewConflictService crewConflictService;

    /**
     * 进入页面
     * @return
     */
    @RequestMapping(value = "", method={ RequestMethod.GET})
   // @RequiresPermissions("crew:crewConflict:list")
    String toCrewConflictPage(){
        return PREFIX + "/crewConflictList";
    }

    /**
    * 多条件模糊 查询并且分页显示
    * @param crewConflict
    * @param offset
    * @param limit
    * @return
    */
    @RequestMapping(value = "/list")
    @ResponseBody
    //@RequiresPermissions("crew:crewConflict:list")
    public Page list(CrewConflict crewConflict, String offset, String limit) {
        Page page = new Page();
        page.setPageNumber((Integer.valueOf(offset) / (Integer.valueOf(limit))));
        page.setPageSize(Integer.valueOf(limit));
        page = crewConflictService.list(crewConflict, page);
        return page;
    }

    /**
     * 进入新增页面
     * @return
     */
    @RequestMapping(value = "/add", method={ RequestMethod.GET})
   // @RequiresPermissions("crew:crewConflict:add")
    String add(){
        return PREFIX + "/crewConflictAdd";
    }

    /**
     * 保存
     * @param crewConflict
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method={ RequestMethod.POST})
    //@RequiresPermissions("crew:crewConflict:add")
    public R save(CrewConflict crewConflict, HttpServletRequest request){
//        User user = (User)request.getSession().getAttribute("currentUser");
        if(crewConflictService.insert(crewConflict) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 进入编辑页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit", method={ RequestMethod.GET})
    //@RequiresPermissions("crew:crewConflict:edit")
    String edit(Model model,Integer id){
        CrewConflict crewConflict = crewConflictService.get(id);
        model.addAttribute("crewConflict", crewConflict);
        return PREFIX + "/crewConflictEdit";
    }

    /**
     * 修改
     * @param crewConflict
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/update", method={ RequestMethod.POST})
    //@RequiresPermissions("crew:crewConflict:edit")
    public R update( CrewConflict crewConflict,HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("currentUser");
        if(crewConflictService.update(crewConflict)>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 进入查看页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/view", method={ RequestMethod.GET})
    //@RequiresPermissions("crew:crewConflict:list")
    String view(Model model,Integer id){
        CrewConflict crewConflict = crewConflictService.get(id);
        model.addAttribute("crewConflict", crewConflict);
        model.addAttribute("isReadonly", 1);
        return PREFIX + "/crewConflictEdit";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/delete", method={ RequestMethod.POST})
    //@RequiresPermissions("crew:crewConflict:delete")
    public R delete( Integer id){
        if(crewConflictService.delete(id)>0){
            return R.ok();
        }
        return R.error();
    }

}
